<%@ page pageEncoding="utf-8" %>
<%@include file="/commons/taglibs.jsp" %>
<!DOCTYPE html>
<html>
<fmt:bundle basename="res">
<head>
    <meta charset="utf-8">
    <title><fmt:message key='gggl'/></title>
    <jsp:include page="/WEB-INF/commons/commons-header.jsp" flush="true"/>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">

            <div class="layui-form-item">
                <form name="totalForm" id="totalForm">

                    <div class="layui-inline">
                        <label class="layui-form-label" style="width: 80px;"><fmt:message key='ptlx'/></label>
                        <div class="layui-input-inline">
                            <select name="platformType">
                                <option value="0" <c:if test="${params.platformType == 0}">selected</c:if>><fmt:message key='scd'/></option>
                                <option value="1" <c:if test="${params.platformType == 1}">selected</c:if>><fmt:message key='cgd'/></option>
                            </select>
                        </div>
                    </div>



                    <div class="layui-inline">
                        <label class="layui-form-label" style="width: 80px;"><fmt:message key='ggbt'/></label>
                        <div class="layui-input-inline">
                            <input type="text" name="title" value="${params.title}" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label" style="width: 80px;"><fmt:message key='sftj'/></label>
                        <div class="layui-input-inline">
                            <select name="recommend">
                                <option value="0" <c:if test="${params.recommend == 0}">selected</c:if>><fmt:message key='qxz'/></option>
                                <option value="1" <c:if test="${params.recommend == 1}">selected</c:if>><fmt:message key='f'/></option>
                                <option value="2" <c:if test="${params.recommend == 2}">selected</c:if>><fmt:message key='s'/></option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label" style="width: 80px;"><fmt:message key='zt'/></label>
                        <div class="layui-input-inline">
                            <select name="status">
                                <option value="0" <c:if test="${params.status == 0}">selected</c:if>><fmt:message key='qxz'/></option>
                                <option value="1" <c:if test="${params.status == 1}">selected</c:if>><fmt:message key='ysj'/></option>
                                <option value="2" <c:if test="${params.status == 2}">selected</c:if>><fmt:message key='yxj'/></option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-inline">
                        <button class="layui-btn layui-btn-sm layuiadmin-btn-list" id="search"><i class="layui-icon layui-icon-search layuiadmin-button-btn"></i> <fmt:message key='ss'/></button>
                    </div>
                </form>
            </div>
        </div>

    </div>

    <div class="layui-card">
        <div class="layui-field-box layui-form">
            <shiro:hasPermission name="news:create">
                <a href="javascript:void(0);" class="layui-btn layui-btn-sm layui-btn-normal" id="add"><i class="layui-icon">&#xe61f;</i> <fmt:message key='xzgg1'/></a>
            </shiro:hasPermission>
            <shiro:hasPermission name="news:enables">
                <a href="javascript:void(0);" class="layui-btn layui-btn-sm layui-btn-warm" id="enables"><i class="layui-icon">&#xe605;</i> <fmt:message key='plsj'/></a>
            </shiro:hasPermission>
            <shiro:hasPermission name="news:disables">
                <a href="javascript:void(0);" class="layui-btn layui-btn-sm layui-btn-danger" id="disables"><i class="layui-icon">&#x1006;</i> <fmt:message key='plxj'/></a>
            </shiro:hasPermission>

            <table class="layui-table" lay-size="sm">
                <thead>
                <tr>
                    <th width="5%"><input id="checkboxs" type="checkbox" value="${item.id}" lay-ignore lay-skin="primary"/></th>
                    <th width="5%"><fmt:message key='xh'/></th>
                    <th width="25%"><fmt:message key='ggmc1'/></th>
                    <th width="25%"><fmt:message key='cjsj'/></th>
                    <th><fmt:message key='sftj'/></th>
                    <th><fmt:message key='zt'/></th>
                    <th><fmt:message key='cz'/></th>
                </tr>
                </thead>
                <c:forEach items="${page.result}" var="item" varStatus="status">
                    <tr>
                        <td><input type="checkbox" lay-ignore value="${item.id}" class="feijin-check" lay-skin="primary"/></td>
                        <td>${status.index + 1}</td>
                        <td>${item.title}</td>
                        <td><fmt:formatDate value="${item.createTime}" type="both"/></td>
                        <td>
                            <c:if test="${item.recommend == 1}"><b style="color: #f00;"><fmt:message key='f'/></b></c:if>
                            <c:if test="${item.recommend == 2}"><b style="color: green;"><fmt:message key='s'/></b></c:if>
                        </td>
                        <td>
                            <c:if test="${item.status == 1}"><b style="color: #f00;"><fmt:message key='yxj'/></b></c:if>
                            <c:if test="${item.status == 2}"><b style="color: green;"><fmt:message key='ysj'/></b></c:if>
                        </td>
                        <td>
                            <div class="layui-btn-container">
                                <c:choose>
                                    <c:when test="${item.status == 2}">
                                        <shiro:hasPermission name="news:disable">
                                            <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-danger layui-btn-xs feijin-disable"><fmt:message key='xj'/></a>
                                        </shiro:hasPermission>
                                    </c:when>
                                    <c:otherwise>
                                        <shiro:hasPermission name="news:enabled">
                                            <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-normal layui-btn-xs feijin-enabled"><fmt:message key='sj'/></a>
                                        </shiro:hasPermission>
                                    </c:otherwise>
                                </c:choose>
                                <c:choose>
                                    <c:when test="${item.recommend == 2}">
                                        <shiro:hasPermission name="news:notrecommend">
                                            <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-danger layui-btn-xs feijin-notrecommend"><fmt:message key='qxsytj'/></a>
                                        </shiro:hasPermission>
                                    </c:when>
                                    <c:otherwise>
                                        <shiro:hasPermission name="news:recommend">
                                            <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-normal layui-btn-xs feijin-recommend"><fmt:message key='sytj'/></a>
                                        </shiro:hasPermission>
                                    </c:otherwise>
                                </c:choose>
                                <shiro:hasPermission name="news:modify">
                                    <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-normal layui-btn-xs feijin-modify"><fmt:message key='bj'/></a>
                                </shiro:hasPermission>
                                <shiro:hasPermission name="news:remove">
                                    <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-danger layui-btn-xs feijin-remove"><fmt:message key='sc'/></a>
                                </shiro:hasPermission>
                            </div>
                        </td>
                    </tr>
                </c:forEach>
            </table>
            <jsp:include page="/commons/page.jsp" flush="true"/>
        </div>
    </div>

</div>

<script>

    layui.use("layer", function () {

        //添加
        $("#add").click(function () {
            layer.open({
                type: 2,
                title: "<fmt:message key='xzgg1'/>",
                content: "${web_domain}/mall/news/create",
                area: ["90%", "90%"],
                btn: ["<fmt:message key='qd'/>", "<fmt:message key='qx'/>"],
                yes: function (index, layero) {
                    layero.find('iframe').contents().find("#submit").click();
                }
            });
        });

        //编辑
        $(".feijin-modify").click(function () {
            var id = $(this).attr("data-id");
            layer.open({
                type: 2,
                content: "${web_domain}/mall/news/modify?id=" + id,
                area: ["90%", "90%"],
                btn: ["<fmt:message key='qx'/>", "<fmt:message key='qx'/>"],
                yes: function (index, layero) {
                    layero.find('iframe').contents().find("#submit").click();
                }
            });
        });

        //下架
        $(".feijin-disable").click(function () {
            var id = $(this).attr("data-id");
            layer.confirm("<fmt:message key='qrxjm?'/>", function () {
                feijin.put({
                    url: "${web_domain}/mall/news/disable",
                    data: {id: id}
                });
            });
        });

        //上架
        $(".feijin-enabled").click(function () {
            var id = $(this).attr("data-id");
            layer.confirm("<fmt:message key='qrsjm?'/>", function () {
                feijin.put({
                    url: "${web_domain}/mall/news/enable",
                    data: {id: id}
                });
            });
        });

        //推荐
        $(".feijin-recommend").click(function () {
            var id = $(this).attr("data-id");
            layer.confirm("<fmt:message key='qrtjdsym?'/>", function () {
                feijin.put({
                    url: "${web_domain}/mall/news/recommend",
                    data: {id: id}
                });
            });
        });


        //取消推荐
        $(".feijin-notrecommend").click(function () {
            var id = $(this).attr("data-id");
            layer.confirm("<fmt:message key='qrqxtjm?'/>", function () {
                feijin.put({
                    url: "${web_domain}/mall/news/notRecommend",
                    data: {id: id}
                });
            });
        });


        //删除
        $(".feijin-remove").click(function () {
            var id = $(this).attr("data-id");
            layer.confirm("<fmt:message key='qrscm?'/>", function () {
                feijin.delete({
                    url: "${web_domain}/mall/news/remove",
                    data: {"id": id}
                });
            });
        })

        //全选反选
        $("#checkboxs").click(function () {
            if (this.checked) {
                $(".feijin-check:checkbox").prop("checked", true);
            } else {
                $(".feijin-check:checkbox").prop("checked", false);
            }
        });


        //批量上架账号
        $("#enables").click(function () {
            var ids = [];

            $(".feijin-check:checkbox:checked").each(function (index, item) {
                var id = $(item).val();
                ids.push(id);
            });

            if (ids.length === 0) {
                layer.msg('<fmt:message key='qxgxxyczdjl'/>');
                return false;
            }

            layer.confirm("<fmt:message key='qrsjxzdggm?1'/>", function () {
                feijin.put({
                    url: "${web_domain}/mall/news/enables",
                    data: {"data": ids.join(";")}
                });
            });
        });

        //批量下架账号
        $("#disables").click(function () {
            var ids = [];

            $(".feijin-check:checkbox:checked").each(function (index, item) {
                var id = $(item).val();
                ids.push(id);
            });

            if (ids.length === 0) {
                layer.msg('<fmt:message key='qxgxxyczdjl'/>');
                return false;
            }

            layer.confirm("<fmt:message key='qrxjxzdggm?1'/>", function () {
                feijin.put({
                    url: "${web_domain}/mall/news/disables",
                    data: {"data": ids.join(";")}
                });
            });
        });

    });
</script>
</body>
</fmt:bundle>
</html>
